 import * as API_AfterSale from '../../api/after-sale.js'
 import { Foundation } from '../../ui-utils/index.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeId:0,
    afterSaleList:[],
    afterSaleRecordList:[],//售后记录
    params:{
      page_no:1,
      page_size:10
    },
    paramslist : {
      page_no: 1,
      page_size: 10,
      order_status: "REFUND"
    },
    finished:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getAfterSale()
  },
  // switchTab(event) {
  //   let index = parseInt(event.currentTarget.dataset.index);
  //   if (index === 1 && index !== this.data.typeId) {
  //     this.setData({
  //       'params_shops.page_no': 1,
  //       afterSaleRecordList: [],
  //       typeId: index,
  //       finished: false,
  //       // pageCount: 0
  //     })
  //     this.getAfterSale()
  //   }
  //   if (index === 0 && index !== this.data.typeId){
  //     this.setData({
  //       'params_goods.page_no': 1,
  //       afterSaleList: [],
  //       typeId: index,
  //       finished:false,
  //       // pageCount:0
  //     })
  //     this.getAfterSale()
  //   }
  // },
  getAfterSale(){
    if(this.data.typeId===0){
      API_AfterSale.getAfterSaleRecord(this.data.params).then(response=>{
        let { data } = response
        if(data && data.length){
          data.forEach(key=>{
            key.refund_price = Foundation.formatPrice(key.refund_price)
            key.create_time = Foundation.unixToDate(key.create_time)
          })
          // this.data.afterSaleList.push(...data)
          this.setData({ afterSaleList: this.data.afterSaleList.concat(data) })
        }else{
          this.setData({finished:true})
        }
      })
    }
  //   if(this.data.typeId===0){
  //     API_AfterSale.getAfterSale(this.data.paramslist).then(response=>{
  //       let { data } = response
  //       if(data && data.length){
  //         data.forEach(key=>{
  //           // key.refund_price = Foundation.formatPrice(key.refund_price)
  //           key.create_time = Foundation.unixToDate(key.create_time)
  //         })
  //         // this.data.afterSaleList.push(...data)
  //         this.setData({ afterSaleRecordList: this.data.afterSaleRecordList.concat(data) })
  //       }else{
  //         this.setData({finished:true})
  //       }
  //     })
  //   }
  },
  onReachBottom: function () {
    if (!this.data.finshed) {
      this.setData({ "params.page_no": this.data.params.page_no + 1 })
      this.getAfterSale()
    } else {
      return
    }
  }
})